package ru.urfc.portal.ui.client.controllers;

import java.util.List;

import ru.urfc.portal.ui.client.controllers.loaders.GridLoader;
import ru.urfc.portal.ui.client.controllers.loaders.LoaderWithPagingListenter;
import ru.urfc.portal.ui.client.descriptor.GridDescriptor;
import ru.urfc.portal.ui.client.widgets.BaseFilter;

import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.toolbar.PagingToolBar;

public class GridController extends BaseController {
	
	private GridLoader loader;

	public GridController(GridDescriptor descriptor) {
		super(descriptor);
	}

	@Override
	protected GridLoader createLoader(GridDescriptor descriptor) {
		loader = new GridLoader(descriptor);
		loader.addLoadListener(new LoaderWithPagingListenter() {
			@Override
			public void onLoad(List<ModelData> data) {
				GridController.this.onLoad(data);
			}
		});
		return loader;
	}
	
	protected void onLoad(List<ModelData> data) {
	}

	public ListStore<ModelData> createStore() {
		return new ListStore<ModelData>(loader);
	}

	public void setFilter(BaseFilter filter) {
		loader.setFilter(filter);
	}

	public void setPaging(PagingToolBar paging) {
       	paging.bind(loader);
	}
	
}
